﻿using B.S.Backtrack.Domain.Entities;
using B.S.Backtrack.ErrorCode;
using B.S.Backtrack.Infrastructure.Interface;
using B.S.Backtrack.Read.API.Application.Command.Proces;
using MediatR;

namespace B.S.Backtrack.Read.API.Application.CommandHandler.Proces
{
    public class QueryProcessingHandler : IRequestHandler<QueryProcessingCommand, ApiResult<List<Processing>>>
    {
        private readonly IBaseRepository<Processing> proRep;

        public QueryProcessingHandler(IBaseRepository<Processing> proRep)
        {
            this.proRep = proRep;
        }
        public Task<ApiResult<List<Processing>>> Handle(QueryProcessingCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<Processing>> result = new ApiResult<List<Processing>>();
            var list = proRep.GetAll().Where(x => x.ProductId == request.ProductId);
            result.Code = ApiEnums.查询成功;
            result.Msg = ApiEnums.查询成功.ToString();
            result.Data = list.ToList();
            return Task.FromResult(result);
        }
    }
}
